package com.ruoyi.web.controller.laiqianba.merchant;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.db.domain.MerchantTaskInfo;
import com.ruoyi.merchant.service.IMerchantTaskInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商户推送任务Controller
 * 
 * @author ruoyi
 * @date 2023-08-12
 */
@RestController
@RequestMapping("/merchant/taskInfo")
public class MerchantTaskInfoController extends BaseController
{
    @Autowired
    private IMerchantTaskInfoService merchantTaskInfoService;

    /**
     * 查询商户推送任务列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:taskInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantTaskInfo merchantTaskInfo)
    {
        startPage();
        List<MerchantTaskInfo> list = merchantTaskInfoService.selectMerchantTaskInfoList(merchantTaskInfo);
        return getDataTable(list);
    }


    /**
     * 导出商户推送任务列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:taskInfo:export')")
    @Log(title = "商户推送任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantTaskInfo merchantTaskInfo)
    {
        List<MerchantTaskInfo> list = merchantTaskInfoService.selectMerchantTaskInfoList(merchantTaskInfo);
        ExcelUtil<MerchantTaskInfo> util = new ExcelUtil<MerchantTaskInfo>(MerchantTaskInfo.class);
        util.exportExcel(response, list, "商户推送任务数据");
    }

    /**
     * 获取商户推送任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:taskInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(merchantTaskInfoService.selectMerchantTaskInfoById(id));
    }


    /**
     * 新增商户推送任务
     */
    @PreAuthorize("@ss.hasPermi('merchant:taskInfo:add')")
    @Log(title = "商户推送任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantTaskInfo merchantTaskInfo)
    {
        return toAjax(merchantTaskInfoService.insertMerchantTaskInfo(merchantTaskInfo));
    }

    /**
     * 修改商户推送任务
     */
    @PreAuthorize("@ss.hasPermi('merchant:taskInfo:edit')")
    @Log(title = "商户推送任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantTaskInfo merchantTaskInfo)
    {
        return toAjax(merchantTaskInfoService.updateMerchantTaskInfo(merchantTaskInfo));
    }

    /**
     * 删除商户推送任务
     */
    @PreAuthorize("@ss.hasPermi('merchant:taskInfo:remove')")
    @Log(title = "商户推送任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merchantTaskInfoService.deleteMerchantTaskInfoByIds(ids));
    }

    /**
     * 更新任务状态
     * @param merchantTaskInfo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('merchant:baseInfo:edit')")
    @Log(title = "商户基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody MerchantTaskInfo merchantTaskInfo) {
        return toAjax(merchantTaskInfoService.updateMerchantTaskInfo(merchantTaskInfo));
    }

}
